Prior   Atan2   Next

There is a computer function (and on many modern calculators) named $\text{atan2}(y,x)$ that will return a correct angle from the signed rise and run data that went into getting a slope. Use two points on the line and compute $y$ and $x$ as $$\left[\begin{array}{c} y\\ x \end{array}\right]=\left[\begin{array}{c} y_{1}-y_{2}\\ x_{1}-x_{2} \end{array}\right]$$ I have shown these upside down, $y$ first and $x$ second, because that is how many computer implementations of the functions require them. (But! There are plenty of exceptions where the order of input is $\text{atan2}(x,y)$ instead of $\text{atan2}(y,x).$ Buyer beware.) The result of the atan2 function for line AC is shown in the figure. Effectively, the angle returned is the angle that the line would make with the $x$-axis if it were extended to meet that axis.

If you want the returned angle to be between $0$ and $\pi$, then $y$ must be positive. If $y<0$, the returned angle will be between $-\pi$ and $0$. Also, the returned value will always be in the interval $-\pi<\theta<\pi$.

ArcTangent 2
Atan2. The four panels show the result of using atan2 with input of the $y,x$ coordinates of line segment $AC.$ The function returns an angle that is measured from the right side of point A at the horizontal and going counter clockwise or clockwise, depending on the sign of the y input. Consequently, the function will return an angle in the range of $-\pi\le0\le\pi.$ In the figure, angles in the 3rd and 4th quadrant are returned as negative values and to show positive angles, we must add the negative value to $2\pi.$